<?php
namespace app\wxapp\controller;

use think\Controller;
use think\Request;
use think\Cache;

class Base extends Controller{

    protected $token;

    protected $user;

    /**
     *
     */
    public function _initialize(){

        //登录检查
        $request = Request::instance();
        $token = $request->header("Authentication");

        $token = decode_token($token);
        $token = json_decode($token,true);
        if(!$token || empty($token['openid'])){
            $this->error('你还没有登录');
        }

        $login_data = Cache::get($token['openid']);
        $expire_time = $login_data['expire_time'];
        if($expire_time < time()){
            $this->error("登录超时 请重新登录");
        }
        $this->user = $login_data['user'];
        $this->token = $token;
    }
}